//
//  phoneHistoryCell.m
//  智慧小区
//
//  Created by lab603 on 15/7/7.
//  Copyright (c) 2015年 Dreamsoul. All rights reserved.
//

#import "phoneHistoryCell.h"
#import "Phone.h"
#import "PhoneFrame.h"
#define cellBorder 10
@interface phoneHistoryCell()
//电话归属地描述
@property (nonatomic,weak)UILabel *descriptionLabel;
//电话号码
@property (nonatomic,weak)UILabel *phoneLabel;
//拨打按钮
@property (nonatomic,weak)UIButton *playBtn;
@end
@implementation phoneHistoryCell
+ (instancetype)cellWithTableView:tableView{
    static NSString *ID = @"phoneCell";
    phoneHistoryCell * cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (cell==nil) {
        cell = [[phoneHistoryCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID];
        cell.accessoryType = UITableViewCellAccessoryNone;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return cell;
}
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        //电话归属描述
        UILabel *descriptionLabel = [[UILabel alloc] init];
        descriptionLabel.textColor = [UIColor grayColor];
        descriptionLabel.backgroundColor = [UIColor clearColor];
        descriptionLabel.font = [UIFont systemFontOfSize:15.0];
        [self.contentView addSubview:descriptionLabel];
        _descriptionLabel = descriptionLabel;
        //电话label
        UILabel *phoneLabel = [[UILabel alloc] init];
        phoneLabel.textColor = [UIColor grayColor];
        phoneLabel.backgroundColor = [UIColor clearColor];
        phoneLabel.font = [UIFont systemFontOfSize:15.0];
        [self.contentView addSubview:phoneLabel];
        _phoneLabel = phoneLabel;
        //提醒按钮
        UIButton *playBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [playBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [playBtn setTitle:@"拨打" forState:UIControlStateNormal];
        [playBtn setBackgroundColor:APP_THEME_COLOR];
        playBtn.titleLabel.font = [UIFont systemFontOfSize:13.0];
        [playBtn.layer setCornerRadius:CORNER_RADIUS_5];
        playBtn.clipsToBounds = YES;
        [playBtn addTarget:self action:@selector(phonePlay) forControlEvents:UIControlEventTouchUpInside];
        [self.contentView addSubview: playBtn];
        _playBtn = playBtn;
    }
    return self;
}
- (void)setPhoneFrame:(PhoneFrame *)phoneFrame{
    _phoneFrame = phoneFrame;
    Phone *phone = phoneFrame.phone;
    //为控件赋值和设置Frame
    self.descriptionLabel.frame = phoneFrame.descriptionLabelF;
    self.phoneLabel.frame = phoneFrame.phoneLabelF;
    self.playBtn.frame = phoneFrame.playBtnF;
    
    self.descriptionLabel.text = phone.Description;
    self.phoneLabel.text = phone.phone;
}
- (void)phonePlay{
    IWLog(@"%@",@"拨打号码");
    if (self.tapPhonePlayBlock) {
        self.tapPhonePlayBlock(self.phoneFrame);
    }
    
}
- (void)setFrame:(CGRect)frame
{
    frame.origin.y += cellBorder;
    frame.size.height -= cellBorder;
    [super setFrame:frame];
}
@end
